package com.emm.yixun.mobile.ui.selectcustomers;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.adapter.CustomerAdapter;
import com.emm.yixun.mobile.adapter.ScreenONEAdapter;
import com.emm.yixun.mobile.adapter.ScreenTWOAdapter;
import com.emm.yixun.mobile.application.EmmApplication;
import com.emm.yixun.mobile.base.BaseActivity;
import com.emm.yixun.mobile.model.GetConsultantList;
import com.emm.yixun.mobile.model.GetCustomerList;
import com.emm.yixun.mobile.model.GetCustomerList.CustomerList;
import com.emm.yixun.mobile.model.GetDictionaryList;
import com.emm.yixun.mobile.model.GetDictionaryList.RqBusNumList;
import com.emm.yixun.mobile.model.ScreenOneModel;
import com.emm.yixun.mobile.model.ScreenOneModel.Info;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.swu.pulltorefresh.PullToRefreshSwipeMenuListView;
import cn.swu.pulltorefresh.PullToRefreshSwipeMenuListView.IXListViewListener;
import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;
import xf.tools.Loading;

/**
 * 
 * <p>
 * <b>Title：</b> 客户选择界面
 * </p>
 * <p>
 * <b>Description：</b>
 * </p>
 * 
 * @author tangxin
 * @date 2016年12月6日 下午4:17:02
 */
public class SelectcustomersActivity extends SwipeBackActivity implements IXListViewListener {

	private static final String TAG = "SelectcustomersActivity";

	/** 刷新侧滑菜单listview */
	PullToRefreshSwipeMenuListView swip_list;

	/** 适配器 */
	CustomerAdapter adapter;

	ImageView icon2, icon1;

	/** 排序 */
	LinearLayout sort_textview;

	TextView colors_text, colors_text2;

	/** 筛选 */
	LinearLayout screen_textview;

	/** 菜单 */
	PopupWindow morePopu;

	/** 菜单 */
	View view;

	/** 排序 */
	View viewsort;

	/** 排序 */
	PopupWindow popusort;

	/** 筛选 */
	View viewscreen;

	/** 筛选 */
	PopupWindow popuscreen;

	/** 指派 */
	View viewzp;

	/** 指派 */
	PopupWindow popuzp;

	/** 标题 */
	TextView title_main;

	LinearLayout select_fs;

	/** 是否是批量选择状态 true不是 false 是 */
	public boolean select_bl = false;

	/** 确定按钮 */
	Button sure_btn;

	/** 选中项 */
	CustomerList date = new CustomerList();

	/** 是否存在选中的 */
	boolean isselect = false;

	/** 返回按钮 */
	ImageView back_btn;

	/** 侧滑关闭框架 */
	private SwipeBackLayout mSwipeBackLayout;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		BaseActivity.activity = this;
		setContentView(R.layout.selectcustormer_activity);

		SetSwipeBackLayout(mSwipeBackLayout);

		initView();

		SetRelativiLayoutPadding(R.id.select_custormer);

		initBtn();
		Loading.showDialogForLoading(SelectcustomersActivity.this, "正在加载...", false, true, 60000);
		getCustomerList("" + setselect, "", "", "" + pageNumber, "" + pageSize, 1);
		getConsultantList();
		getDictionaryList();
	}

	@Override
	protected void onResume() {
		super.onResume();
		BaseActivity.activity = this;
	}

	private void initView() {
		sort_textview = (LinearLayout) findViewById(R.id.sort_textview);
		colors_text = (TextView) findViewById(R.id.colors_text);
		colors_text2 = (TextView) findViewById(R.id.colors_text2);
		icon1 = (ImageView) findViewById(R.id.icon1);
		icon2 = (ImageView) findViewById(R.id.icon2);
		screen_textview = (LinearLayout) findViewById(R.id.screen_textview);
		title_main = (TextView) findViewById(R.id.title_main);
		title_main.setText(getString(R.string.cosutmoer));
		swip_list = (PullToRefreshSwipeMenuListView) findViewById(R.id.listView);
		sure_btn = (Button) findViewById(R.id.sure_btn);
		select_fs = (LinearLayout) findViewById(R.id.select_fs);
		back_btn = (ImageView) findViewById(R.id.back_btn);
		swip_list.setPullRefreshEnable(true);
		swip_list.setPullLoadEnable(true);
		swip_list.setXListViewListener(this);
		swip_list.setRefreshTime(EmmApplication.getData("RefreshTime"));
	}

	private void initBtn() {
		back_btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		sort_textview.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				colors_text.setTextColor(Color.parseColor("#FD593E"));
				colors_text2.setTextColor(Color.parseColor("#3E3C3D"));
				icon1.setImageResource(R.drawable.paixu_down);
				icon2.setImageResource(R.drawable.shaixuan_up);
				SetsortPopu();
			}
		});
		screen_textview.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				colors_text.setTextColor(Color.parseColor("#3E3C3D"));
				colors_text2.setTextColor(Color.parseColor("#FD593E"));
				icon1.setImageResource(R.drawable.paixu_up);
				icon2.setImageResource(R.drawable.shaixuan_down);
				Setscreen_create();
			}
		});
		swip_list.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				Log.w(TAG, "a--" + position);
				if (position == 0) {// 不处理
				} else {// 否则减去头部占用的一个位置
					position--;
					if (select_bl) {
					} else {
						isselect = true;
						ArrayList<CustomerList> list = adapter.getArraylist();
						for (int i = 0; i < list.size(); i++) {
							list.get(i).setIsselect(false);
						}
						adapter.SetDate(list);
						adapter.SELECTAlone(position);
						date.setCustomerName(list.get(position).getCustomerName());
						date.setMobile(list.get(position).getMobile());
						date.setCustomerId(list.get(position).getCustomerId());
					}
				}
				Log.w(TAG, "b--" + position);
			}
		});
		sure_btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (isselect) {
					Intent intent = new Intent();
					intent.putExtra("customerId", date.getCustomerId());
					intent.putExtra("customerName", date.getCustomerName());
					intent.putExtra("customerPhone", date.getMobile());
					setResult(141, intent);
					finish();
				} else {
					EmmApplication.T2("还未选择客户");
				}
			}
		});
	}

	/** 刷新 */
	@Override
	public void onRefresh() {
		swip_list.stopLoadMore();
		h.sendEmptyMessage(1);
	}

	/** 加载更多 */
	@Override
	public void onLoadMore() {
		swip_list.stopRefresh();
		h.sendEmptyMessage(2);
	}

	/** 模拟加载效果 */
	Handler h = new Handler() {
		public void handleMessage(android.os.Message msg) {
			if (msg.what == 1) {
				pageNumber = 1;
				getCustomerList("" + setselect, itemid1, itemid2, "" + 1, "" + pageSize, 1);

			} else if (msg.what == 2) {
				pageNumber++;
				getCustomerList("" + setselect, itemid1, itemid2, "" + pageNumber, "" + pageSize, 2);
			}
		};
	};

	/** 排序选择标识 */
	private int setselect = 2;

	/** 排序菜单 */
	public void SetsortPopu() {
		viewsort = LayoutInflater.from(SelectcustomersActivity.this).inflate(R.layout.popu_sort, null);
		popusort = new PopupWindow(viewsort, android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT,
				android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT);
		popusort.setFocusable(true);
		popusort.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
		popusort.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
		popusort.showAtLocation(sort_textview, Gravity.TOP, 0, 0);
		popusort.setFocusable(true);
		popusort.setOutsideTouchable(true);
		viewsort.setFocusable(true);
		viewsort.setFocusableInTouchMode(true);
		viewsort.setOnKeyListener(new OnKeyListener() {
			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				if (keyCode == KeyEvent.KEYCODE_BACK) {
					popusort.dismiss();
					EmmApplication.setLog(SelectcustomersActivity.this);
				}
				return false;
			}
		});
		viewsort.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				popusort.dismiss();
				EmmApplication.setLog(SelectcustomersActivity.this);
			}
		});
		// 最新创建
		TextView new_creaete = (TextView) viewsort.findViewById(R.id.new_creaete);
		// 最新更新
		TextView new_update = (TextView) viewsort.findViewById(R.id.new_update);
		// 最新跟进
		TextView new_fgo = (TextView) viewsort.findViewById(R.id.new_fgo);
		// 按标星
		TextView number_star = (TextView) viewsort.findViewById(R.id.number_star);
		ImageView g1 = (ImageView) viewsort.findViewById(R.id.g1);
		ImageView g2 = (ImageView) viewsort.findViewById(R.id.g2);
		ImageView g3 = (ImageView) viewsort.findViewById(R.id.g3);
		ImageView g4 = (ImageView) viewsort.findViewById(R.id.g4);
		g1.setVisibility(setselect == 1 ? View.VISIBLE : View.INVISIBLE);
		g2.setVisibility(setselect == 2 ? View.VISIBLE : View.INVISIBLE);
		g3.setVisibility(setselect == 3 ? View.VISIBLE : View.INVISIBLE);
		g4.setVisibility(setselect == 4 ? View.VISIBLE : View.INVISIBLE);
		new_creaete.setTextColor(setselect == 1 ? Color.parseColor("#FD593E") : Color.parseColor("#494949"));
		new_update.setTextColor(setselect == 2 ? Color.parseColor("#FD593E") : Color.parseColor("#494949"));
		new_fgo.setTextColor(setselect == 3 ? Color.parseColor("#FD593E") : Color.parseColor("#494949"));
		number_star.setTextColor(setselect == 4 ? Color.parseColor("#FD593E") : Color.parseColor("#494949"));
		new_creaete.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				popusort.dismiss();
				EmmApplication.setLog(SelectcustomersActivity.this);
				setselect = 1;
				pageNumber = 1;
				Loading.showDialogForLoading(SelectcustomersActivity.this, "正在加载...", false, true, 60000);
				getCustomerList();
			}
		});
		new_update.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				popusort.dismiss();
				EmmApplication.setLog(SelectcustomersActivity.this);
				setselect = 2;
				pageNumber = 1;
				Loading.showDialogForLoading(SelectcustomersActivity.this, "正在加载...", false, true, 60000);
				getCustomerList();
			}
		});
		new_fgo.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				popusort.dismiss();
				EmmApplication.setLog(SelectcustomersActivity.this);
				setselect = 3;
				pageNumber = 1;
				Loading.showDialogForLoading(SelectcustomersActivity.this, "正在加载...", false, true, 60000);
				getCustomerList();
			}
		});
		number_star.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				popusort.dismiss();
				EmmApplication.setLog(SelectcustomersActivity.this);
				setselect = 4;
				pageNumber = 1;
				Loading.showDialogForLoading(SelectcustomersActivity.this, "正在加载...", false, true, 60000);
				getCustomerList();
			}
		});
	}

	private void getCustomerList() {
		getCustomerList("" + setselect, itemid1, itemid2, "" + pageNumber, "" + pageSize, 1);
	}

	/** 主 */
	private int select_id = 0;

	/** 次 */
	private int select_id2 = 0;

	/** 筛选主菜单ID */
	String itemid1 = "1";

	/** 筛选子菜单ID */
	String itemid2;

	/**
	 * <p>
	 * <b>Title：</b> 筛选
	 * </p>
	 * <p>
	 * <b>Description：</b> 每项筛选类型添加一项 全部，重构方法
	 * </p>
	 * 
	 * @author tangxin
	 * @date 2016年12月29日 上午10:55:17
	 */
	public void Setscreen_create() {
		viewscreen = LayoutInflater.from(SelectcustomersActivity.this).inflate(R.layout.popu_screen, null);
		popuscreen = new PopupWindow(viewscreen, android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT,
				android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT);
		popuscreen.setFocusable(true);
		popuscreen.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
		popuscreen.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
		popuscreen.showAtLocation(sort_textview, Gravity.TOP, 0, 0);
		popuscreen.setFocusable(true);
		popuscreen.setOutsideTouchable(true);
		viewscreen.setFocusable(true);
		viewscreen.setFocusableInTouchMode(true);

		viewscreen.setOnKeyListener(new OnKeyListener() {
			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				if (keyCode == KeyEvent.KEYCODE_BACK) {
					popuscreen.dismiss();
					EmmApplication.setLog(SelectcustomersActivity.this);
				}
				return false;
			}
		});

		viewscreen.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				popuscreen.dismiss();
				EmmApplication.setLog(SelectcustomersActivity.this);
			}
		});

		ListView screen_listview1 = (ListView) viewscreen.findViewById(R.id.screen_listview1);
		ListView screen_listview2 = (ListView) viewscreen.findViewById(R.id.screen_listview2);

		final List<ScreenOneModel> listm = new ArrayList<ScreenOneModel>();

		// 初始化展示数据
		for (int i = 0; i < 5; i++) {
			ScreenOneModel sd = new ScreenOneModel();
			List<Info> listc = new ArrayList<Info>();
			if (i == 0) {
				sd.setName1("客户状态");
				sd.setNameid1("1");

				Info n0 = new Info();
				n0.setName2("全部");
				n0.setNameid("0");
				listc.add(n0);

				Info n = new Info();
				n.setName2("问询");
				n.setNameid("1");
				listc.add(n);

				Info n1 = new Info();
				n1.setName2("来访");
				n1.setNameid("2");
				listc.add(n1);

				if ("1".equals(EmmApplication.getData(EmmApplication.FROMDETAILSTYPE))) {// 拥有认筹权限
					Info n2 = new Info();
					n2.setName2("认筹");
					n2.setNameid("3");
					listc.add(n2);
				}

				Info n4 = new Info();
				n4.setName2("认购");
				n4.setNameid("4");
				listc.add(n4);

				Info n6 = new Info();
				n6.setName2("签约");
				n6.setNameid("5");
				listc.add(n6);

				Info n7 = new Info();
				n7.setName2("无意向");
				n7.setNameid("6");
				listc.add(n7);

				sd.setInfo(listc);
				listm.add(sd);
			} else if (i == 1) {
				sd.setName1("意向等级");
				sd.setNameid1("2");

				Info n0 = new Info();
				n0.setName2("全部");
				n0.setNameid("0");
				listc.add(n0);

				Info n = new Info();
				n.setName2("A+");
				n.setNameid("1");
				listc.add(n);

				Info n1 = new Info();
				n1.setName2("A");
				n1.setNameid("2");
				listc.add(n1);

				Info n2 = new Info();
				n2.setName2("B");
				n2.setNameid("3");
				listc.add(n2);

				Info n3 = new Info();
				n3.setName2("C");
				n3.setNameid("4");
				listc.add(n3);

				Info n4 = new Info();
				n4.setName2("D");
				n4.setNameid("5");
				listc.add(n4);
				sd.setInfo(listc);
				listm.add(sd);
			} else if (i == 2) {
				sd.setName1("跟进时间");
				sd.setNameid1("3");

				Info n0 = new Info();
				n0.setName2("全部");
				n0.setNameid("0");
				listc.add(n0);

				Info n = new Info();
				n.setName2("3天未跟进");
				n.setNameid("1");
				listc.add(n);

				Info n1 = new Info();
				n1.setName2("一周未跟进");
				n1.setNameid("2");
				listc.add(n1);

				Info n2 = new Info();
				n2.setName2("两周未跟进");
				n2.setNameid("3");
				listc.add(n2);

				Info n3 = new Info();
				n3.setName2("一月未跟进");
				n3.setNameid("4");
				listc.add(n3);

				Info n4 = new Info();
				n4.setName2("两月未跟进");
				n4.setNameid("5");
				listc.add(n4);
				sd.setInfo(listc);
				listm.add(sd);
			} else if (i == 3) {
				sd.setName1("首次接触方式");
				sd.setNameid1("4");

				Info n0 = new Info();
				n0.setName2("全部");
				n0.setNameid("0");
				listc.add(n0);

				if (FirstContactMode != null && FirstContactMode.size() > 0) {
					for (int y = 0; y < FirstContactMode.size(); y++) {
						Info n = new Info();
						n.setName2(FirstContactMode.get(y).getDictionaryName());
						n.setNameid(FirstContactMode.get(y).getDictionaryId());
						listc.add(n);
					}
					sd.setInfo(listc);
				} else {
				}

				listm.add(sd);
			} else if (i == 4) {
				sd.setName1("归属人");
				sd.setNameid1("5");

				Info n0 = new Info();
				n0.setName2("全部");
				n0.setNameid("0");
				listc.add(n0);

				if (getconsultan != null && getconsultan.getConsultantList() != null) {
					if (getconsultan.getConsultantList().size() > 0) {
						for (int n = 0; n < getconsultan.getConsultantList().size(); n++) {
							Info info = new Info();
							info.setName2(getconsultan.getConsultantList().get(n).getConsultantUserName());
							info.setNameid(getconsultan.getConsultantList().get(n).getConsultantUserId());
							listc.add(info);
						}
						sd.setInfo(listc);
					} else {
					}
				} else {
				}
				listm.add(sd);
			}
		}

		final ScreenONEAdapter adapter = new ScreenONEAdapter(SelectcustomersActivity.this, listm);
		final ScreenTWOAdapter adapter2 = new ScreenTWOAdapter(SelectcustomersActivity.this, listm.get(select_id)
				.getInfo());

		// 绑定适配器
		screen_listview1.setAdapter(adapter);
		screen_listview2.setAdapter(adapter2);

		// 默认选择一项
		screen_listview1.setSelection(select_id);
		adapter.SetSelect(select_id);
		adapter2.SetSelect(select_id2);
		screen_listview2.setSelection(select_id2);

		// 主筛选列表监听
		screen_listview1.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				adapter2.getDate(listm.get(arg2).getInfo(), select_id2);
				select_id = arg2;
				select_id2 = 0;

				itemid1 = listm.get(arg2).getNameid1();

				// 刷新主筛选列表的展示界面
				adapter.SetSelect(select_id);
				// 刷新次级筛选列表数据，以当前主筛选列表选中项为主键
				adapter2.SetSelect(select_id2);

			}
		});

		// 次级筛选列表监听
		screen_listview2.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				popuscreen.dismiss();
				EmmApplication.setLog(SelectcustomersActivity.this);
				select_id2 = arg2;

				// 刷新次级筛选列表的展示界面
				adapter2.SetSelect(select_id2);

				itemid2 = listm.get(select_id).getInfo().get(arg2).getNameid();

				pageNumber = 1;
				clearlist();
				// 调用接口数据，重新渲染客户列表

				Loading.showDialogForLoading(SelectcustomersActivity.this, "正在加载...", false, true, 60000);
				getCustomerList("" + setselect, itemid1, itemid2, "" + pageNumber, "" + pageSize, 1);

			}
		});
	}

	private void clearlist() {
		getcustomer = new GetCustomerList();
		if (adapter == null) {
			adapter = new CustomerAdapter(SelectcustomersActivity.this, null);
			swip_list.setAdapter(adapter);
		} else {
			adapter.SetDate(null);
		}
		adapter.GetIsv(true);
	}

	/** 客户列表 */
	GetCustomerList getcustomer;

	/** 页码 */
	int pageNumber = 1;

	/** 页码条数 */
	int pageSize = 10;

	boolean IsLoading = true;

	/**
	 * 客户列表<br>
	 * sort 排序<br>
	 * screenType 筛选类型<br>
	 * screenValue 筛选类型对应值 <br>
	 * pageNumber 页码<br>
	 * pageSize 页码大小 opentype 1 刷新 2 加载
	 */
	private void getCustomerList(String sort, String screenType, String screenValue, String pageNumberd,
			String pageSized, final int opentype) {
		if (!EmmApplication.isErrorCode()) {
			EmmApplication.T();
			return;
		}
		EmmApplication.updateUrl("getCustomerList");
		Map<String, String> map = new HashMap<String, String>();
		map.put("version", EmmApplication.getPackageManager(5));
		map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
		map.put("token", EmmApplication.getToken());
		map.put("userId", EmmApplication.getUserId());
		map.put("terminalCode", EmmApplication.getPackageManager(2));
		map.put("projectCode", EmmApplication.getProjectCode());
		map.put("type", "");// 此处不传
		map.put("sort", sort);
		if (EmmApplication.isNull(screenType)) {
			map.put("screenType", screenType);
		} else {
			map.put("screenType", "");
		}
		if (EmmApplication.isNull(screenValue)) {
			map.put("screenValue", screenValue);
		} else {
			map.put("screenValue", "");
		}
		map.put("pageNumber", pageNumberd);
		map.put("pageSize", pageSized);

		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("params", map);
		JSONObject json = new JSONObject(paramsMap);
		String jsonstr = json.toString();
		RequestParams params = new RequestParams();
		params.put("body", jsonstr);
		Log.v("getCustomerList-->post", EmmApplication.urlStr + "?body=" + jsonstr);
		AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
		asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
			@Override
			public void onFailure(Throwable error, String content) {
				super.onFailure(error, content);
				Loading.hideDialogForLoading();
				Log.v(TAG, "请求结束error:" + error + "==" + content);
				swip_list.stopRefresh();
				String timed = EmmApplication.dataTime(EmmApplication.geTime(), "yyyy-MM-dd HH:mm");
				swip_list.setRefreshTime(timed);
				swip_list.stopLoadMore();
				EmmApplication.setData("RefreshTime", timed);
			}

			@Override
			public void onFinish() {
				Loading.hideDialogForLoading();
				Log.v(TAG, "请求结束");
				Loading.hideDialogForLoading();
				swip_list.stopRefresh();
				swip_list.stopLoadMore();
				String timed = EmmApplication.dataTime(EmmApplication.geTime(), "yyyy-MM-dd HH:mm");
				swip_list.setRefreshTime(timed);
				EmmApplication.setData("RefreshTime", timed);
				super.onFinish();
			}

			@Override
			public void onStart() {
				super.onStart();
				Log.v(TAG, "请求开始");
			}

			@Override
			public void onSuccess(String content) {
				super.onSuccess(content);
				if (content == null) {
					return;
				}
				Log.v("content", content);
				JSONObject jsonObj = JSONObject.parseObject(content);
				JSONObject resData = (JSONObject) jsonObj.get("resData");
				if (resData == null) {
					Log.v(TAG, "信息返回值为空");
					return;
				}

				GetCustomerList getcust = JSONObject.parseObject(resData.toString(), GetCustomerList.class);
				if ("1".equals(getcust.getResult())) {
					Log.v("获取成功", "");
					if (getcust.getCustomerList() != null) {
						if (opentype == 1) {// 刷新
							getcustomer = new GetCustomerList();
							getcustomer = getcust;
						} else {// 加载
							if (getcustomer != null) {
								getcustomer.getCustomerList().addAll(getcust.getCustomerList());
							} else {
								getcustomer = new GetCustomerList();
								getcustomer.getCustomerList().addAll(getcust.getCustomerList());
							}
						}
						if (getcustomer.getCustomerList().size() < (pageNumber * pageSize)) {// 代表没有更多
							IsLoading = false;
							if (opentype != 1) {
								// EmmApplication.T("没有更多客户");
							}
						}
						if (adapter == null) {
							adapter = new CustomerAdapter(SelectcustomersActivity.this, getcustomer.getCustomerList());
							swip_list.setAdapter(adapter);
						} else {
							adapter.SetDate(getcustomer.getCustomerList());
						}
					} else {
						if (pageNumber > 0 && opentype != 1)
							pageNumber--;
						if (opentype == 1) {
							// EmmApplication.T("没有查询到客户");
						} else {
							// EmmApplication.T("没有更多客户");
						}
						ArrayList<CustomerList> arrlist;
						if (null != getcustomer && null != getcustomer.getCustomerList()) {
							arrlist = getcustomer.getCustomerList();
						} else {
							arrlist = new ArrayList<GetCustomerList.CustomerList>();
						}

						if (adapter == null) {
							adapter = new CustomerAdapter(SelectcustomersActivity.this, arrlist);
							swip_list.setAdapter(adapter);
						} else {
							adapter.SetDate(arrlist);
						}
					}
					adapter.GetIsv(true);
				} else {
					try {
						EmmApplication.T(getcust.getErrorMsg().toString());
						Log.v("获取失败", "errorCode:" + getcust.getErrorCode().toString() + "errorMsg:"
								+ getcust.getErrorMsg().toString());
					} catch (NullPointerException e) {
						Log.v("客户列表，错误信息获取空指针异常", "");
					}
				}
			}
		});
	}

	/** 查询置业顾问列表数据源 */
	GetConsultantList getconsultan;

	/** 查询置业顾问列表 */
	private void getConsultantList() {
		EmmApplication.updateUrl("getConsultantList");
		Map<String, String> map = new HashMap<String, String>();
		map.put("resourcesCode", "menu_0006_0001");
		map.put("searchType", "0");
		map.put("version", EmmApplication.getPackageManager(5));
		map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
		map.put("token", EmmApplication.getToken());
		map.put("userId", EmmApplication.getUserId());
		map.put("terminalCode", EmmApplication.getPackageManager(2));
		map.put("projectId", EmmApplication.getProjectID());
		map.put("projectCode", EmmApplication.getProjectCode());
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("params", map);
		JSONObject json = new JSONObject(paramsMap);
		String jsonstr = json.toString();
		RequestParams params = new RequestParams();
		params.put("body", jsonstr);
		Log.v("getConsultantList-->post", EmmApplication.urlStr + "?body=" + jsonstr);
		AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
		asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
			@Override
			public void onFailure(Throwable error, String content) {
				super.onFailure(error, content);
				Log.v(TAG, "请求结束error:" + error + "==" + content);
			}

			@Override
			public void onFinish() {
				Log.v(TAG, "请求结束");
				super.onFinish();
			}

			@Override
			public void onStart() {
				super.onStart();
				Log.v(TAG, "请求开始");
			}

			@Override
			public void onSuccess(String content) {
				super.onSuccess(content);
				if (content == null) {
					return;
				}
				Log.v("置业顾问content", content);
				JSONObject jsonObj = JSONObject.parseObject(content);
				JSONObject resData = (JSONObject) jsonObj.get("resData");
				if (resData == null) {
					Log.v(TAG, "信息返回值为空");
					return;
				}

				getconsultan = JSONObject.parseObject(resData.toString(), GetConsultantList.class);
				if ("1".equals(getconsultan.getResult())) {
					Log.v("获取成功", "");
				} else {
					EmmApplication.T(getconsultan.getErrorMsg().toString());
					try {
						Log.v("获取失败", "errorCode:" + getconsultan.getErrorCode().toString() + "errorMsg:"
								+ getconsultan.getErrorMsg().toString());
					} catch (NullPointerException e) {
						Log.v("查询置业顾问", "错误信息获取空指针异常");
					}
				}
			}
		});
	}

	ArrayList<RqBusNumList> FirstContactMode;

	/** 字典数据源 */
	GetDictionaryList getdiction;

	/** 查询字典列表接口 */
	private void getDictionaryList() {
		EmmApplication.updateUrl("getDictionaryList");
		Map<String, String> map = new HashMap<String, String>();
		map.put("version", EmmApplication.getPackageManager(5));
		map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
		map.put("token", EmmApplication.getToken());
		map.put("userId", EmmApplication.getUserId());
		map.put("terminalCode", EmmApplication.getPackageManager(2));
		map.put("busNumType", "11");
		map.put("busNum", "01");
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("params", map);
		JSONObject json = new JSONObject(paramsMap);
		String jsonstr = json.toString();
		RequestParams params = new RequestParams();
		params.put("body", jsonstr);
		Log.v("getDictionaryList-->post", EmmApplication.urlStr + "?body=" + jsonstr);
		AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
		asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
			@Override
			public void onFailure(Throwable error, String content) {
				super.onFailure(error, content);
				Log.v(TAG, "请求结束error:" + error + "==" + content);
			}

			@Override
			public void onFinish() {
				Log.v(TAG, "请求结束");
				super.onFinish();
			}

			@Override
			public void onStart() {
				super.onStart();
				Log.v(TAG, "请求开始");
			}

			@Override
			public void onSuccess(String content) {
				super.onSuccess(content);
				if (content == null) {
					return;
				}
				Log.v(TAG, "content==:" + content);
				JSONObject jsonObj = JSONObject.parseObject(content);
				JSONObject resData = (JSONObject) jsonObj.get("resData");
				if (resData == null) {
					Log.v(TAG, "信息返回值为空");
					return;
				}
				getdiction = JSONObject.parseObject(resData.toString(), GetDictionaryList.class);
				if ("1".equals(getdiction.getResult())) {
					FirstContactMode = getdiction.getRqBusNumList();
				} else {
					EmmApplication.T(getdiction.getErrorMsg().toString());
					Log.v("获取失败", "errorCode:" + getdiction.getErrorCode().toString() + "errorMsg:"
							+ getdiction.getErrorMsg().toString());
				}
			}
		});
	}

}
